<template>
	<view class="pages_intelligence" :style="{paddingTop: `${search.height+search.top+10}px`}">
		<myTabs :title="title" @goBlack="goBlack" :mybackgroundColor="'#FFDA2D'"></myTabs>
		<view class="recordsHeard">
			<image class="recordsHeardImg" src="/static/img/clickIcon.png"></image>
			<view class="recordsHeardTop">章鱼菜品大数据中心</view>
			<view class="recordsHeardBotton">更新时间：{{updatTime}}</view>
			<view class="recordsHeardBotton">可点击菜品名称查看详情</view>
		</view>
		<view class="recordsHeardTiao">
			<view @click="goPatch(`/package/citySelection/index?isText=3`)" class="recordsHeardTiaoItems">
				<span>{{location.name}}</span>
				<image src="/static/img/bottomIcon.png"></image>
			</view>
			<view @click="goPatch(`/package/category/index?isText=1`)" class="recordsHeardTiaoItems">
				<span>{{variety.children[0].label}}</span>
				<image src="/static/img/bottomIcon.png"></image>
			</view>
		</view>
		<view class="recordsHeardTiaoBox">
			<view class="recordsHeardTiaoBox_top">
				<span @click="updataType(1)" :class="type==1 ? 'act' : ''">推荐菜品</span>
				<span @click="updataType(2)" :class="type==2 ? 'act' : ''">重点菜品</span>
				<span @click="updataType(3)" :class="type==3 ? 'act' : ''">重点食材</span>
			</view>
		</view>

		<view class="dataTaberBox" v-if="isLoading">
			<view class="dataTaberBox_newItems" @click="goPath(item)" v-for="(item,index) in analyseData" :key="index">
				<view class="dataTaberBox_newItemsHeard">
					<view class="dataTaberBox_newItemsHeardLeft">
						<span>{{index+1}}</span>
						<span v-if="type==3">{{item.foodName | ff_foodNameTure}}</span>
						<span v-else>{{item.foodName}}</span>
					</view>
					<view class="dataTaberBox_newItemsHeardRight">
						<span>查看详情</span>
						<image src="/static/img/rightIcon.png"></image>
					</view>
				</view>
				<view class="dataTaberBox_newItemsBody">
					<view class="dataTaberBox_newItemsBodyItems">
						<span>菜品指数</span>
						<span :class="item.trend=='上升' ? '' : 'green'">{{item.marketIndex.toFixed(2)}}</span>
					</view>
					<view class="dataTaberBox_newItemsBodyItems">
						<span>菜品趋势</span>
						<view class="dataTaberBox_newItemsBodyItemsIndex">
							<span v-if="type != 3"
								:class="item.trend=='上升' ? '' : 'green'">{{item.increaseIndex.toFixed(2)}}%</span>
							<span v-else
								:class="item.trend=='上升' ? '' : 'green'">{{item.trend=='上升' ? '' : '-'}}{{item.increaseIndex.toFixed(2)}}%</span>
							<image :src="item.trend=='上升' ? '/static/img/UpIcon.png' : '/static/img/downIcon.png'">
							</image>
						</view>
					</view>
				</view>
				<view class="recordsHeardTiaoBox_text" v-if="type==1">
					综合建议：考虑上新时重点关注<span :style="{color : '#FF8940'}">{{item.foodName}}</span>，
					<span :style="{color : '#FF8940'}">{{moth}}</span>
					月该产品热度较高，较上月平均热度增幅
					<span :style="{color : '#FF8940'}">{{item.increaseIndex.toFixed(2)}}%</span>
				</view>
				<view class="recordsHeardTiaoBox_text" v-else-if="type==2">
					综合建议：建议打造产品时重点关注<span :style="{color : '#FF8940'}">{{item.foodName}}</span>，
					<span :style="{color : '#FF8940'}">{{moth}}</span>
					月该产品数据表现较好，热度较高，较上月平均热度增幅
					<span :style="{color : '#FF8940'}">{{item.increaseIndex.toFixed(2)}}%</span>
				</view>
				<view class="recordsHeardTiaoBox_text" v-else-if="type==3">
					综合建议：本月请重点关注<span :style="{color : '#FF8940'}">{{item.foodName}}</span>食材，由这些食材打造的菜品
					<span :style="{color : '#FF8940'}">{{moth}}</span>
					月数据表现较好，热度较高，较上月平均热度增幅
					<span
						:style="{color : '#FF8940'}">{{item.trend=='上升' ? '' : '-'}}{{item.increaseIndex.toFixed(2)}}%</span>
				</view>
			</view>
		</view>
		<view class="dataTaberBox mydataTaberBox" v-else>
			<empty :isP="false" text="数据" myImg="/static/img/mykongIcon.png" :myMarginTop="20"></empty>
		</view>
	</view>

</template>

<script>
	// import SimpleDateTimePicker from "uni_modules/buuug7-simple-datetime-picker/components/buuug7-simple-datetime-picker/buuug7-simple-datetime-picker.vue";

	import myTabs from "@/components/myTabs/index.vue"
	import empty from "@/components/empty/index.vue"
	export default {
		components: {
			myTabs,
			empty,
			// SimpleDateTimePicker
		},
		data() {
			return {
				title: '章鱼菜品大数据中心',
				isLoading: 1,
				analyseData: [],
				type: 0,
				birthday: '',
				moth: 0,
				variety: null,
				pageNum: 1,
				tatol: 0,
				foodAdvise: null,
				textAdvise: '',
				updatTime: '',
				endYear: '',
				endMonth: ''
			}
		},
		onLoad(oprtions) {
			// #ifndef H5
			let search = uni.getMenuButtonBoundingClientRect()
			this.$store.commit('updataSearch', search);
			// #endif
			let nowDate = new Date();
			this.endMonth = nowDate.getMonth() + 1;
			if (oprtions) {
				this.type = oprtions.type == "newFoods" ? 1 : oprtions.type == "mainFoods" ? 2 : oprtions.type ==
					"followIngredients" ? 3 : '';

				let nowDate = new Date(oprtions.month);
				this.moth = nowDate.getMonth() + 1;
				this.updatTime = this.$Tools.handleTime(nowDate);
				// this.endYear = nowDate.getFullYear();
				let moth = nowDate.getMonth() + 1 < 10 ? `0${nowDate.getMonth()+1}` : nowDate.getMonth() + 1;
				this.birthday = `${nowDate.getFullYear()}${moth}`;

			}
			this.initAnalyseData().then(res => {
				// this.getConclusion();
			})


		},
		onShow(options) {
			this.variety = uni.getStorageSync('variety');
			if (options) {
				this.pageNum = 1;
				this.analyseData = [];
				this.initAnalyseData().then(res => {
					// this.getConclusion();
				})
			}
		},
		computed: {
			search() {
				return this.$store.state.search;
			},
			location() {
				return this.$store.state.location;
			},

		},
		filters: {
			ff_foodNameTure(item) {
				console.log()
				if (item.indexOf(',') != -1) {
					return item.split(',')[0]
				} else {
					return item
				}

			},
			ff_analyseData(data) {

				let nowData = [];
				data.forEach(item => {
					nowData.push(item.foodName)
				});
				nowData = Array.from(new Set(nowData))
				return nowData.splice(',')
			},
			ff_analyseDataNum(data) {
				let nowData = [];
				data.forEach(item => {
					nowData.push(item.foodName)
				});
				nowData = Array.from(new Set(nowData))
				return nowData.length
			}
		},
		methods: {
			goPath(item) {
				if (this.type == 3) {
					if (item.foodsId == '' || !item.foodsId) {
						uni.showToast({
							title: '敬请期待',
							mask: true,
							icon: 'none'
						})
						return
					}
				} else {
					if (item.foodId == 0 || !item.foodId) {
						uni.showToast({
							title: '敬请期待',
							mask: true,
							icon: 'none'
						})
						return
					}
				}

				uni.navigateTo({
					url: `/package/cuisineDetail/index?dataId=${item.dataId}&index=${this.type}`
				})
			},
			getConclusion() {
				let location = uni.getStorageSync('location');
				let variety = uni.getStorageSync('variety');
				let req = {
					cityId: location.id,
					month: this.birthday,
					categoryId: variety.children[0].id
				}

				this.$api.getFoodAdvise(req).then(res => {
					this.foodAdvise = res.data;
					this.updataType(this.type);
					console.log("res.data['newFoods']", res.data)
					this.updatTime = this.$Tools.handleTime(res.data['newFoods'].month);
					let nowDate = new Date(res.data['newFoods'].month);
					this.moth = nowDate.getMonth() + 1 < 10 ? `0${nowDate.getMonth()+1}` : nowDate.getMonth() + 1;
				})
			},
			goAdd() {
				this.pageNum++;
				this.initAnalyseData();
			},
			goPatch(url) {
				uni.navigateTo({
					url
				})
			},
			updataType(type) {

				// this.textAdvise = this.type==1 ? this.foodAdvise.advise : this.type==2 ? this.foodAdvise.adviseMain : this.type==3 ? this.foodAdvise.adviseIngredient : '';

				if (this.analyseData) {
					let zonNum = 0;
					let junNum = 0;

					this.analyseData.forEach(item => {
						zonNum = zonNum + item.marketIndex;
					})
					junNum = zonNum / this.analyseData.length;
					this.textAdvise = `${(junNum/zonNum*100).toFixed(2)}%`;
					console.log('this.textAdvise', this.textAdvise)

				}


				if (type == this.type) {
					return
				}
				this.type = type;
				this.pageNum = 1;
				this.analyseData = []
				this.initAnalyseData();
			},
			// 打开picker
			openDatetimePicker() {
				this.$refs.myPicker.show();
			},

			// 关闭picker
			closeDatetimePicker() {
				this.$refs.myPicker.hide();
			},

			handleSubmit(e) {
				this.birthday = `${e.year}${e.month}`;
				// this.moth = e.month <10 ? e.month.charAt(e.month.length - 1) : e.month;
				this.pageNum = 1;
				this.analyseData = []
				this.initAnalyseData()
			},
			initAnalyseData() {
				return new Promise((ress, rejj) => {
					uni.showLoading({
						title: '加载中',
						mask: true
					})
					let location = uni.getStorageSync('location');
					this.variety = uni.getStorageSync('variety');
					let req = {
						cityId: location.id,
						categoryId: this.variety.children[0].id,
						month: this.birthday,
						type: this.type,
					}
					this.$api.getFoodList(req).then(res => {
						if (res.code == 200) {
							uni.hideLoading();
							this.analyseData = [...this.analyseData, ...res.rows];
							this.isLoading = this.analyseData.length ? 1 : 0;
							this.tatol = res.total;
							ress();
							this.updataType(this.type);
						}
					})
				})

			},
			goBlack() {
				uni.navigateBack();
			}
		}
	}
</script>
<style lang="scss" scoped>
	.pages_intelligence {
		background-color: #F0F0F0;
		min-height: 100vh;
		box-sizing: border-box;

		.recordsHeard {

			width: 100%;
			height: 160rpx;
			position: relative;
			padding: 20rpx 45rpx;
			box-sizing: border-box;
			background-color: #FFDA2D;

			image {
				position: absolute;
				top: 0;
				left: 0;
				width: 100%;
				height: 100%;
			}

		}

		/deep/.picker-body {
			picker-view-column {
				display: none;
			}

			picker-view-column:nth-child(1) {
				display: block;
			}

			picker-view-column:nth-child(2) {
				display: block;
			}
		}

		.recordsHeardTop {

			height: 44rpx;
			font-size: 32rpx;
			font-family: 蘋方-簡;
			font-weight: bold;
			line-height: 44rpx;
			color: #333333;
			margin-bottom: 8rpx;
		}

		.recordsHeardBotton {
			height: 34rpx;
			font-size: 28rpx;
			font-family: PingFang SC;
			font-weight: 400;
			line-height: 34rpx;
			color: #666666;
		}

		.recordsHeardTiao {
			display: flex;
			padding: 24rpx 0;
			background-color: #fff;
			border-bottom: 1rpx solid #ededed;
			box-sizing: border-box;

		}

		.recordsHeardTiaoItems {
			display: flex;
			justify-content: center;
			flex: 1;
			align-items: center;
			font-weight: bold;

			image {
				width: 24rpx;
				height: 24rpx;
				margin-left: 4rpx;
			}

			span {
				display: inline-block;
				height: 40rpx;
				font-size: 28rpx;
				font-family: 蘋方-簡;
				font-weight: 550;
				line-height: 40rpx;
				color: #333333;
			}
		}

		.recordsHeardTiaoItems:nth-child(1) {
			border-right: 2rpx solid #ddd;
		}

		.recordsHeardTiaoBox {
			// padding: 0 32rpx;
			box-sizing: border-box;
			background-color: #fff;
			border-radius: 0px 0px 24rpx 24rpx
		}


		.recordsHeardTiaoBox_top {
			display: flex;
			justify-content: space-evenly;
			padding: 20rpx 0;
			// border-bottom: 1rpx solid #e6e6e6;

			span {
				display: inline-block;
				width: 212rpx;
				height: 64rpx;
				line-height: 64rpx;
				background: rgba(255, 218, 45, 0.2);
				/* border: 2rpx solid #FFDA2D; */
				opacity: 1;
				border-radius: 8rpx;
				font-size: 28rpx;
				font-family: 蘋方-簡;
				font-weight: normal;
				color: #333333;
				text-align: center;
				font-weight: bold;
			}

			.act {
				background: #FFDA2D;
			}
		}

		.recordsHeardTiaoBox_text {
			font-size: 24rpx;
			font-family: 蘋方-簡;
			font-weight: 400;
			line-height: 34rpx;
			color: #333333;
			border-radius: 16rpx;
			padding: 16rpx;
			box-sizing: border-box;
			background-color: #fffbe6;
		}

		.dataTaberBox_newItemsBodyItems {
			flex: 1;
			text-align: center;
			display: flex;
			flex-direction: column;

			span {
				display: inline-block;
			}

			&>span:nth-child(1) {
				height: 34rpx;
				font-size: 24rpx;
				font-family: PingFang SC;
				font-weight: 400;
				line-height: 34rpx;
				color: #a59c9c;
				margin-bottom: 6rpx;
			}

			&>span:nth-child(2) {
				height: 44rpx;
				font-size: 36rpx;
				font-family: DIN;
				font-weight: bold;
				line-height: 44rpx;
				color: #FF471C;
			}
		}

		.dataTaberBox_newItemsBody {
			display: flex;
			margin: 40rpx 0 24rpx 0;

			image {
				width: 26rpx;
				height: 36rpx;
			}
		}

		.dataTaberBox_newItemsHeardRight {
			height: 34rpx;
			display: flex;
			align-items: center;
			flex: 0 0 125rpx;

			span {
				display: inline-block;
				height: 34rpx;
				line-height: 34rpx;
				font-size: 24rpx;
			}

			image {
				width: 24rpx;
				height: 24rpx;
			}
		}

		.dataTaberBox_newItemsBodyItemsIndex {
			display: flex;
			align-items: center;
			justify-content: center;

			span {
				display: inline-block;
				height: 44rpx;
				font-size: 36rpx;
				font-family: DIN;
				font-weight: bold;
				line-height: 44rpx;
				color: #FF471C;
				margin-right: 6rpx;
			}
		}

		.green {
			color: #3AD346 !important;
		}

		.dataTaberBox_newItemsHeardLeft {
			height: 56rpx;
			line-height: 56rpx;
			display: flex;
			align-items: center;
			justify-content: space-around;
			overflow: hidden;
			margin-right: 20rpx;

			span {
				display: inline-block;
			}

			span:nth-child(1) {
				border-radius: 50%;
				width: 56rpx;
				font-size: 36rpx;
				font-family: DIN;
				font-weight: 550;
				color: #333333;
				background-color: #FFDA2D;
				margin-right: 12rpx;
				text-align: center;
			}

			span:nth-child(2) {
				font-size: 32rpx;
				font-family: 蘋方-簡;
				font-weight: 550;
				color: #333333;
				flex: 1;
				white-space: nowrap;
				overflow: hidden;
				text-overflow: ellipsis;

			}

		}

		.dataTaberBox_newItemsHeard {
			display: flex;
			justify-content: space-between;
			width: 100%;
			align-items: center;

		}

		.dataTaberBox_newItems {
			width: 686rpx;
			background: #fff;
			border: 2rpx solid #FFDA2D;
			border-radius: 24rpx;
			box-sizing: border-box;
			padding: 24rpx;
			margin-bottom: 20rpx;
		}

		.dataTaberBox {
			padding: 24rpx 32rpx;
			box-sizing: border-box;
		}

		.dataTaberBox_heard {
			border-radius: 24rpx 24rpx 0px 0px;
			padding-bottom: 8rpx;
			display: flex;
			padding-top: 24rpx;
			box-sizing: border-box;
			background-color: #fff;
		}

		.dataTaberBoxItems01 {
			flex: 0 0 190rpx;
			width: 190rpx;
			height: 32rpx;
			font-size: 22rpx;
			font-family: PingFang SC;
			font-weight: 400;
			line-height: 32rpx;
			color: #999999;
			margin-right: 38rpx;
			text-align: center;

		}

		.dataTaberBoxItems02 {
			flex: 0 0 88rpx;
			height: 32rpx;
			font-size: 22rpx;
			font-family: PingFang SC;
			font-weight: 400;
			line-height: 32rpx;
			color: #999999;
			margin-right: 48rpx;
		}

		.dataTaberBoxItems03 {
			flex: 0 0 44rpx;
			height: 32rpx;
			font-size: 22rpx;
			font-family: PingFang SC;
			font-weight: 400;
			line-height: 32rpx;
			color: #999999;
			margin-right: 30rpx;
		}

		.dataTaberBoxItems04 {
			width: 113rpx;
			flex: 0 0 113rpx;
			height: 32rpx;
			font-size: 22rpx;
			font-family: PingFang SC;
			font-weight: 400;
			line-height: 32rpx;
			color: #999999;
			margin-right: 48rpx;
			text-align: center;

		}

		.dataTaberBoxBotton {
			width: 100%;
			height: 120rpx;
			padding-top: 24rpx;
			box-sizing: border-box;
			background: #fff;
			display: flex;
			justify-content: center;

			span {
				display: inline-block;
				width: 162rpx;
				height: 48rpx;
				border: 1rpx solid #999999;
				border-radius: 8rpx;
				font-size: 28rpx;
				text-align: center;
				font-family: PingFang SC;
				font-weight: 400;
				line-height: 48rpx;
				color: #999999;
			}
		}

		.dataTaberBoxItems05 {
			flex: 1;
			height: 32rpx;
			font-size: 22rpx;
			font-family: PingFang SC;
			font-weight: 400;
			line-height: 32rpx;
			color: #999999;
			padding-right: 32rpx;
			overflow: hidden;
			box-sizing: border-box;
			display: flex;
			// justify-content: space-around;
			align-items: center;
			text-align: left;

			image {
				flex: 0 0 24rpx;
				width: 24rpx;
				height: 24rpx;
				display: inline-block;
			}
		}

		.white {
			background: #fff !important;
		}

		.dataTaberBox_heardItems {
			display: flex;
			height: 84rpx;
			// padding: 32rpx;
			box-sizing: border-box;
			align-items: center;
			background: #f7f7f7;

			.dataTaberBoxItems01 {
				display: flex;
				// justify-content: space-between;
				align-items: center;
				padding-left: 32rpx;
				box-sizing: border-box;

				span:nth-child(1) {
					width: 40rpx;
					flex: 0 0 40rpx;
					height: 40rpx;
					font-size: 22rpx;
					border-radius: 8rpx;
					font-size: 20rpx;
					font-family: 蘋方-簡;
					font-weight: normal;
					line-height: 40rpx;
					text-align: center;
					color: #333333;
					// background: #F0F0F0;
					margin-right: 15rpx;
				}

				span:nth-child(2) {
					height: 34rpx;
					font-size: 22rpx;
					font-family: 蘋方-簡;
					font-weight: normal;
					line-height: 34rpx;
					color: #333333;
					overflow: hidden;
					white-space: nowrap;
					text-overflow: ellipsis;
				}
			}

			.dataTaberBoxItems02 {
				height: 34rpx;
				font-size: 22rpx;
				font-family: 蘋方-簡;
				font-weight: normal;
				line-height: 34rpx;
				color: #333333;
				text-align: center;
			}

			.dataTaberBoxItems04 {
				height: 34rpx;
				font-size: 22rpx;
				font-family: 蘋方-簡;
				font-weight: normal;
				line-height: 34rpx;
				color: #333333;
				overflow: hidden;
				white-space: nowrap;
				text-overflow: ellipsis;
				text-align: center;
			}

			.dataTaberBoxItems05 {

				span {
					flex: 1;
					display: inline-block;
					height: 34rpx;
					font-size: 22rpx;
					font-family: 蘋方-簡;
					font-weight: normal;
					line-height: 34rpx;
					color: #333333;
					overflow: hidden;
					text-overflow: ellipsis;
					white-space: nowrap;
				}
			}

			.dataTaberBoxItems03 {
				display: flex;
				justify-content: center;

				image {
					width: 44rpx;
					height: 38rpx;
				}
			}

		}
	}
</style>
